package com.zdp.others;

public class 相邻m数的和的最小值 {
    public static void main(String[] args) {
        相邻m数的和的最小值 demo = new 相邻m数的和的最小值();
        System.out.println(demo.getMin(new int[]{10, 4, 1}, 3));
    }

    public int getMin(int[]src,int m){
        if(m<=0||m>src.length){
            return 0;
        }
        int count = 0;
        for(int i=0;i<m-1;i++){
            count += src[i];
        }
        int min = Integer.MAX_VALUE;
        for(int i=m-1;i< src.length;i++){
            min = min<(count+src[i])?min:count+src[i];
            count = count - src[i-m+1]+src[i];
        }
        return min;
    }
}
